package com.anxin.act.process.service;

import java.util.List;

import com.anxin.common.utils.StringUtils;
import com.anxin.framework.web.entity.AjaxResult;
import com.anxin.framework.web.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anxin.act.process.dao.WfMenuProcessDao;
import com.anxin.act.process.entity.WfMenuProcess;

/**
 * 菜单流程配置Service业务层处理
 *
 * @author jbs
 * @date 2020-03-10
 */
@Service
public class WfMenuProcessService extends BaseService<WfMenuProcessDao,WfMenuProcess>{

    @Autowired
    private WfMenuProcessDao wfMenuProcessDao;

    /**
     * 查询菜单流程配置
     *
     * @param id 菜单流程配置ID
     * @return 菜单流程配置
     */
    public WfMenuProcess getById(String id){
        return wfMenuProcessDao.getById(StringUtils.symbolHandler(id));
    }

    /**
     * 查询菜单流程配置列表
     *
     * @param wfMenuProcess 菜单流程配置
     * @return 菜单流程配置
     */
    public List<WfMenuProcess> findList(WfMenuProcess wfMenuProcess){
        return wfMenuProcessDao.findList(wfMenuProcess);
    }



    /**
     * 保存菜单流程配置
     *
     * @param wfMenuProcess 菜单流程配置
     * @return 结果
     */
    public int update(WfMenuProcess wfMenuProcess){
        return super.save(wfMenuProcess);
    }


    /**
     * 删除菜单流程配置信息
     *
     * @param id 菜单流程配置ID
     * @return 结果
     */
    public int deleteById(String id){
        return wfMenuProcessDao.deleteById(id);
    }

    /**
     * 根据菜单标识获取流程标识
     * @param menuKey
     * @return
     */
    public AjaxResult getProcessKey(String menuKey){
        String resProcDefKey = "act_free_flow_approval";
        String processKey = this.getMenuProcess(menuKey);

        if (StringUtils.isNotBlank(processKey)){
            resProcDefKey = processKey;
        }

        return AjaxResult.setSuccessData(resProcDefKey);
    }

    /**
     * 根据菜单标识获取流程标识
     * @param menuKey
     * @return
     */
    public String getMenuProcess(String menuKey){
        String procDefKey = "";

        WfMenuProcess wfMenuProcess = dao.getProcessKey(menuKey);

        if (wfMenuProcess != null && StringUtils.isNotBlank(wfMenuProcess.getProcDefKey())){
            procDefKey = wfMenuProcess.getProcDefKey();
        }
        return procDefKey;
    }


}
